﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Watcher;
using Watcher.AMQ;
using Watcher.AMQ.Objects;

namespace Watcher
{
    
    public class DataSimulation
    {
        private static bool _running = true;
        public bool Running
        {
            set { _running = value; }
            get { return _running; }
        }
        SimulationPublisher sp;
        private static DataSimulation instance; 
        static double x = 0.0;
        static double y = 0.0;
        static double z = 0.0;
        private static TestData td;
        public TestData Td
        {
            get { return td; }
            set {  }
        }
        static readonly object _locker = new object();
        DataProvider _dp;
        public void StartSimulation()
        {
            _dp = DataProvider.getInstance();
            while (_running)
            {
                z = Math.Tan(z + 0.05);
                x = y * Math.Cos(z);
                y = Math.Sin(z);

                TestData td = new TestData(z, y, x);

                double temp = z;
                z = x;
                x = y;
                y = temp;
                _dp.DataList.Add(td);
                Thread.Sleep(100);
                sp.SendMessage("Message:" + x + " | " + y + " | " + z);
            }
            
        }
        public int Data;
        public void ShowData()
        {
            Console.WriteLine("Instance thread procedure. Data={0}", Data);
        }

        public static DataSimulation GetInstance()
        {
            if (instance == null)
                instance = new DataSimulation();
            return instance;
        }
        DataSimulation()
        {
            sp = new SimulationPublisher("parameters", "tcp://localhost:61616");
        }

        public TestData CreateData()
        {
            z = Math.Tan(z + 0.05);
            x = y * Math.Cos(z);
            y = Math.Sin(z);

            td = new TestData(z, y, x);

            double temp = z;
            z = x;
            x = y;
            y = temp;
            return td;
        }
    }
}

